<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
      <title>注册页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/register.css">
    <script src="/js/plugins/form/jquery.form.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/jquery-validation-1.8.1/jquery.validate.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            //数据校验
            $('#registerForm').validate({
                rules:{
                    nickName:{
                        required:true,
                        minlength:2,
                        maxlength:6
                    },
                    email:{
                        required:true,
                        email:true
                    },
                    password:{
                        required:true,
                        minlength:4,
                        maxlength:16
                    },
                    confirmPwd:{
                        required:true,
                        equalTo:"#password"
                    }
                },
                messages:{
                    nickName:{
                        required:"用户必填",
                        minlength:"长度2~6位",
                        maxlength:"长度2~6位"
                    },
                    email:{
                        required:"用户必填",
                        email:"请输入正确的邮箱格式!"
                    },
                    password:{
                        required:"用户必填",
                        minlength:"长度在 4~16 位",
                        maxlength:"长度在 4~16 位"
                    },
                    confirmPwd:{
                        required:"请再输入一次!",
                        equalTo:"两次输入密码不一致!"
                    }
                }
            });
            $('#registerForm').ajaxForm({
                url:baseUrl+"/users",
                success:function (data) {
                    if(data.success){
                        $(document).dialog({
                            type:'confirm',
                            titleText:'温馨提示',
                            content: '注册成功!',
                            overlayClose:true,//点击遮罩层关闭弹窗
                            buttons:[{
                                name:'马上登录',
                                callback:function () {
                                    window.location.href='login.html';
                                }
                            }]
                        });
                        setTimeout(function () {
                            window.location.href='login.html';
                        },3000);
                    }else {
                        $(document).dialog({
                            type:'confirm',
                            titleText:'温馨提示',
                            content: data.errorMsg,
                            autoClose:3000
                        });
                    }
                }
            });
        });
    </script>

</head>
<body>

<div class="container">
    <h5>注册</h5>
    <div class="card card-container ">
        <i id="profile-img" class="fa fa-user-plus fa-5x profile-img" aria-hidden="true"></i>
        <form class="form-signin" id="registerForm" method="post">
            <input type="text" name="nickName" class="form-control badge-pill" placeholder="昵称">
            <input type="email" name="email" class="form-control badge-pill" placeholder="邮箱"  >
            <input id="password" type="password" name="password" class="form-control badge-pill" placeholder="密码">
            <input type="password" name="confirmPwd"  class="form-control badge-pill" placeholder="确认密码">
            <button class="btn btn-lg badge-pill" type="submit" >注册</button>
        </form>
    </div>
    <a href="login.html" class="registerLink">
        已经有账号了？点击此处登录
    </a>
</div>

</body>
</html>
